/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beanControl;

import Utils.Helper;
import Utils.JDBCHelper;
import Utils.StringUtility;
import beanInfo.interestType;
import java.util.ArrayList;
import javax.swing.JTable;

/**
 *
 * @author lyan
 */
public class interestTypeControl {

    ArrayList<String> listColumn = new ArrayList<String>();
    ArrayList<String> listValue = new ArrayList<String>();
    interestType itt = new interestType();

    public void getlistInterstType(JTable table) {

        String sql = "select * from InterestType";
        String[] header = {"InterestTypeID", "InterrestName", "Status"};
        Helper.loadDataTable(sql, table, header);

    }

    public void insertInterstType(interestType itt) {
        Object[] values = {itt.getInterrestName(), itt.getStatus()};
        JDBCHelper.excuteInsertPlaceHolder("InterestType", 2, values);
        Helper.successMessage("Insert  successfull", "wanning");

    }

    public void updateInterstType(interestType itt) {
        String[] objColumn = {"InterrestName", "Status"};
        String[] objValues = {itt.getInterrestName(), itt.getStatus()};


        listColumn = (ArrayList<String>) StringUtility.ArrayToArrayList(objColumn);
        listValue = (ArrayList<String>) StringUtility.ArrayToArrayList(objValues);
        JDBCHelper.executeUpdate("InterestType", listColumn, listValue, "InterestTypeID", String.valueOf(itt.getInterestTypeID()));
        Helper.successMessage("Update Sucessful", "furniture");
    }

    private int checkDelteInterstType(String values) {
        return JDBCHelper.excuteQueryReturnInt("InterestTypeID", "Interest ", values);
    }

    public void DeleteInterstType(interestType itt) {
        if (checkDelteInterstType(String.valueOf(itt.getInterestTypeID())) > 0) {
            Helper.inforMessage("Can not detlete this User", "Wanning");
        } else {
            JDBCHelper.excuteDelete("InterestType", "InterestTypeID", String.valueOf(itt.getInterestTypeID()));
            Helper.successMessage("Delete successfull", "wanning");
        }

    }
}
